import { Component, EventEmitter, OnChanges, OnInit, SimpleChanges, Input, Output } from '@angular/core';

@Component({
  selector: 'el-month-table',
  templateUrl: './month-table.component.html'
})
export class MonthTableComponent implements OnInit, OnChanges {
 @Input() showWeekNumber: boolean = false;
 @Input()  model: number = 0;
 @Input('disabled-date')  disabledDate: any;
 @Output()   modelChange: EventEmitter<number> = new EventEmitter();
 @Input()  currentMonth: number = 0;
 @Input()  date!: Date;
 @Input()   monthRows: Array<any> = [
    ['一月', '二月', '三月', '四月'],
    ['五月', '六月', '七月', '八月'],
    ['九月', '十月', '十一月', '十二月'],
  ];
  constructor() { }

  clickHandle(i: number, k: number): void {
    var /** @type {?} */ monthID = 4 * i + k;
    this.currentMonth = monthID;
    this.date.setMonth(monthID);
    this.modelChange.emit(this.date.getTime());
  };


  isCurrentMonth(i: number, k: number): boolean {
    return this.currentMonth === 4 * i + k;
  };


  ngOnInit(): void {
    this.date = new Date(this.model);
    this.currentMonth = this.date.getMonth();
  };


  ngOnChanges(changes: SimpleChanges): void {
    if (!changes || !changes.model)
      return;
    // first change
    if (changes.model.isFirstChange())
      return;
    this.model = changes.model.currentValue;
    this.date = new Date(this.model);
    this.currentMonth = this.date.getMonth();
  };

}
